// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: Menu Button Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.value1 : object.pressed

// MenuControl aliases
private alias object.value3 : menuControl.currentSelection


// ========================
// Events
// ========================

event ObjectUpdate
	if MenuControl_optionsMenuOpen == false
		temp0 = screen.xsize
		temp0 -= 62
		temp1 = temp0
		temp1 += 48
		CheckTouchRect(0, 0, screen.xsize, screen.ysize)
		if checkResult > -1
			CheckTouchRect(temp0, 172, temp1, 222)
			if checkResult > -1
				object.pressed = true
			else
				object.pressed = false
			end if
		else
			if object.pressed == true
				object.pressed = false
				if menuControl[+1].currentSelection < 22
					keyPress[0].start = true
				else
					keyPress[0].buttonC = true
				end if
			end if
		end if
	end if
end event


event ObjectDraw
	if MenuControl_optionsMenuOpen == false
		temp0 = screen.xsize
		temp0 -= 38
		if menuControl[+1].currentSelection < 22
			if object.pressed == true
				DrawSpriteScreenXY(1, temp0, 202)
			else
				DrawSpriteScreenXY(0, temp0, 202)
			end if
		else
			// On the sound test
			if object.pressed == true
				DrawSpriteScreenXY(3, temp0, 202)
			else
				DrawSpriteScreenXY(2, temp0, 202)
			end if
		end if
	end if
end event


event ObjectStartup
	LoadSpriteSheet("LevelSelect/Icons.gif")

	foreach (TypeName[Menu Button], arrayPos0, ALL_ENTITIES)
		switch engine.deviceType
		case STANDARD
			// If on a standard platform, then touch controls aren't needed
			object[arrayPos0].type = TypeName[Blank Object]
			break

		case MOBILE
			object[arrayPos0].priority = PRIORITY_ACTIVE
			break
			
		end switch
	next
	
	SpriteFrame(-20, -10, 40, 20, 97, 1)	// 0 - Blue `GO` button
	SpriteFrame(-20, -10, 40, 20, 97, 43)	// 1 - Blue large right arrow
	SpriteFrame(-20, -10, 40, 20, 97, 22)	// 2 - Red `GO` button
	SpriteFrame(-20, -10, 40, 20, 97, 64)	// 3 - Red large right arrow
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("LevelSelect/Icons.gif")
	SpriteFrame(-20, -10, 40, 20, 97, 1)	// 0 - Blue `GO` button
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
